package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;

import java.util.*;

public class MediaAdvertisedPlaceAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {
    @Override
    public void set(KiteAttr attr, KiteInst kiteInst, String value, AttrData data) {
        super.set(attr, kiteInst, value, data);
        //广告位
        KiteAttr  adAttr=kiteInst.getAttr("200001149");
        //投放媒体
        KiteAttr  mediaAttr=kiteInst.getAttr("200001150");
        //tx
        List<String> enumsForTenct=new ArrayList<>();
        enumsForTenct.add("100000509");
        enumsForTenct.add("100000568");
        enumsForTenct.add("100000601");
        enumsForTenct.add("100000626");
        enumsForTenct.add("100000642");
        enumsForTenct.add("100000665");
        enumsForTenct.add("100000681");
        enumsForTenct.add("100000696");
        enumsForTenct.add("100000711");
        enumsForTenct.add("100000513");
        //双V
        List<String> enumsForDoubleV=new ArrayList<>();
        enumsForDoubleV.add("100000540");
        enumsForDoubleV.add("100000546");
        enumsForDoubleV.add("100000537");
        //腾讯
        if(Objects.nonNull(adAttr)&&Objects.nonNull(mediaAttr)){
            if(enumsForTenct!=null&&enumsForTenct.size()>0&&enumsForTenct.contains(adAttr.getValue())){
                mediaAttr.setValue("100000507");
            }else if("100000523".equals(adAttr.getValue())){
                //联盟资源
                mediaAttr.setValue("100000567");
            }else if("100000530".equals(adAttr.getValue())){
                //新浪微博
                mediaAttr.setValue("100000602");
            }else if(enumsForDoubleV!=null&&enumsForDoubleV.size()>0&&enumsForDoubleV.contains(adAttr.getValue())){
                //双微
                mediaAttr.setValue("100000629");
            }else if("100000551".equals(adAttr.getValue())){
                //今日头条
                mediaAttr.setValue("100000644");
            }else if("100000552".equals(adAttr.getValue())){
                //抖音
                mediaAttr.setValue("100000660");
            }else if("110007020".equals(adAttr.getValue())){
                //快手
                mediaAttr.setValue("110007019");
            }
        }
        //页面字段展示联动
        String  ggVal = adAttr.getValue();
        String [] ldFldNames = new  String[]{"200002643","200001184","200001185","200001186","200001187","200001188","210004098","200002639","200002640","200002641","200002642","220004292"};
        Set<String> showFldName = new HashSet<>();
        if(KiteStringUtils.equalsAny(ggVal,"100000530","100000537","100000540","100000546")){//新浪&双V
            showFldName.addAll(Arrays.asList(new String[]{"200002643","200001184","200001185","200001186","200001187","200001188"}));
            if(!KiteStringUtils.equals(ggVal,"100000530")){//双V
                showFldName.add("210004098");//原始ID/营业执照主体名称
            }
        }else if(KiteStringUtils.equalsAny(ggVal,"100000665","100000681","100000696","100000711","100000523","100000513")){//腾讯
            showFldName.addAll(Arrays.asList(new String[]{"200001187","200002639","200002640","200002641","200002642","200002643"}));
        }else if(KiteStringUtils.equalsAny(ggVal,"100000552","100000551")){//今日头条抖音
            showFldName.addAll(Arrays.asList(new String[]{"200001187","200002643"}));
        }else if(KiteStringUtils.equalsAny(ggVal,"100000509","100000568","100000601","100000626","100000642")){//微信公众号
            showFldName.addAll(Arrays.asList(new String[]{"210004098"}));
        }else if(KiteStringUtils.equals(ggVal,"110007020")){
            showFldName.addAll(Arrays.asList(new String[]{"200002639","220004292","200002643"}));
        }
        if (!showFldName.isEmpty()){
            for(String ldFld : ldFldNames){
                KiteAttr ldKiteAttr = kiteInst.getAttr(ldFld);
                if(!showFldName.contains(ldFld)){
                    ldKiteAttr.setShowType("E");
                    ldKiteAttr.setIsNull("T");
                }else {
                    ldKiteAttr.setShowType("D");
                    ldKiteAttr.setIsNull("H");
                }
            }
        }else{//没有联动值 全部都不显示
            for(String ldFld : ldFldNames){
                KiteAttr ldKiteAttr = kiteInst.getAttr(ldFld);
                ldKiteAttr.setShowType("D");
                ldKiteAttr.setIsNull("H");
            }
        }

    }
}
